

#ifndef UI_BLOCKWIDGET_H
#define UI_BLOCKWIDGET_H

#include <qwidget.h>
#include <q3listbox.h>
//Added by qt3to4:
#include <QKeyEvent>
#include <QContextMenuEvent>
#include <QPixmap>

#include "pf_blocklist.h"
#include "pf_blocklistobserver.h"

#include "wf_actionhandler.h"
#include "gui_export.h"

/**
 * This is the Qt implementation of a widget which can view a 
 * block list.
 */
class GUI_EXPORT UI_BlockWidget: public QWidget, public PF_BlockListObserver {
    Q_OBJECT

public:
    UI_BlockWidget(WF_ActionHandler* ah, QWidget* parent,
                   const char* name=0, Qt::WFlags f = 0);
    ~UI_BlockWidget();

    void setBlockList(PF_BlockList* blockList) {
        this->blockList = blockList;
        update();
    }

    PF_BlockList* getBlockList() {
        return blockList;
    }

    void update();
    void highlightBlock(PF_Block* block);

    //virtual void blockActivated(PF_Block *) {}
    virtual void blockAdded(PF_Block*) {
        update();
    }
    virtual void blockEdited(PF_Block*) {
        update();
    }
    virtual void blockRemoved(PF_Block*) {
        update();
    }
    virtual void blockToggled(PF_Block*) {
		update();
	}

signals:
	void escape();

public slots:
    //void slotToggleView(QListBoxItem* item);
    void slotActivated(const QString& blockName);
	void slotMouseButtonClicked(int button, Q3ListBoxItem* item, 
		const QPoint& pos);

protected:
    void contextMenuEvent(QContextMenuEvent *e);
	virtual void keyPressEvent(QKeyEvent* e);

private:
    PF_BlockList* blockList;
    Q3ListBox* listBox;
	PF_Block* lastBlock;
    QPixmap pxmVisible;
    QPixmap pxmHidden;
    QPixmap pxmAdd;
    QPixmap pxmRemove;
    QPixmap pxmAttributes;
    QPixmap pxmEdit;
    QPixmap pxmInsert;
    QPixmap pxmDefreezeAll;
    QPixmap pxmFreezeAll;
    WF_ActionHandler* actionHandler;
};

#endif
